package com.hzit.web.test;

import com.hzit.web.bean.Dept;
import com.thoughtworks.xstream.XStream;
import org.junit.Test;

public class XStreamDemo {


    @Test
    public void test01() {

        //java对象转为xml
        Dept dept = new Dept(1, "研发部门", "深圳");

        XStream xStream = new XStream();

        //取别名
        xStream.alias("dept", Dept.class);
        String xml = xStream.toXML(dept);
        System.out.println(xml);


    }

    @Test
    public void test02() {

        //xml转为java对象
        String xml = "<dept>\n" +
                "  <deptno>1</deptno>\n" +
                "  <dname>测试部门</dname>\n" +
                "  <loc>深圳</loc>\n" +
                "</dept>";

        XStream xStream = new XStream();

        //取别名
        xStream.alias("dept", Dept.class);

        Dept dept = (Dept) xStream.fromXML(xml);

        System.out.println(dept);


    }


}
